//
//  GroupActiveHeaderView.m
//  Findif
//
//  Created by Mac on 2019/2/25.
//  Copyright © 2019年 Cicel Chen. All rights reserved.
//

#import "GroupActiveHeaderView.h"

@interface GroupActiveHeaderView ()

@property (nonatomic, weak)UIView * backView;
@property (nonatomic, strong)UIButton * personButton;
@property (nonatomic, strong)UIButton * groupButton;
@property (nonatomic, strong)UIView * personLineView;
@property (nonatomic, strong)UIView * groupLineView;
@property (nonatomic, weak)UIView * lineView;
@property (nonatomic, weak)UIButton * backButton;
@property (nonatomic, weak)UIImageView * searchImageView;
@property (nonatomic, weak)UILabel * searchLabel;

@end

@implementation GroupActiveHeaderView

- (instancetype)initWithFrame:(CGRect)frame{
    
    if ([super initWithFrame:frame]) {
        
        [self setupUI];
    }
    
    return self;
}


- (void)setupUI{
    
    self.backgroundColor = ColorWithRGB(0xF4F5F6);
    self.userInteractionEnabled = YES;
    
    UIView * backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, 45 * SCREENH6)];
    
    backView.backgroundColor = ZRWhiteColor;
    backView.userInteractionEnabled = YES;
    
    self.backView = backView;
    
    [self addSubview:self.backView];
    
    UIView * lineView = [UIView new];
    
    lineView.backgroundColor = ColorWithRGB(0xe4e4e4);
    
    self.lineView = lineView;
    
    [self.backView addSubview:self.lineView];
    
    
    self.personButton = [self setupButtonWithTitle:@"本团活动"];
    self.personButton.selected = YES;
    [self.backView addSubview:self.personButton];
    self.groupButton = [self setupButtonWithTitle:@"我的活动"];
    [self.backView addSubview:self.groupButton];
    
    self.personLineView = [self setupLineView];
    self.personLineView.hidden = NO;
    [self.backView addSubview:self.personLineView];
    self.groupLineView = [self setupLineView];
    [self.backView addSubview:self.groupLineView];
}

- (void)layoutSubviews{
    
    [self.personButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.backView);
        make.leading.mas_equalTo(self.backView).offset(70 * SCREENH6);
    }];
    
    [self.personLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.backView);
        make.height.mas_equalTo(1.5 * SCREENH6);
        make.leading.trailing.mas_equalTo(self.personButton);
    }];
    
    [self.groupButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.backView);
        make.trailing.mas_equalTo(self.backView).offset(-70 * SCREENH6);
    }];
    
    [self.groupLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.backView);
        make.height.mas_equalTo(1.5 * SCREENH6);
        make.leading.trailing.mas_equalTo(self.groupButton);
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.bottom.mas_equalTo(self.backView);
        make.height.mas_equalTo(1 * SCREENH6);
    }];
}


- (UIView *)setupLineView{
    
    UIView * lineView = [UIView new];
    
    lineView.backgroundColor = ColorWithRGB(0xFFD733);
    lineView.hidden = YES;
    
    return lineView;
}


- (UIButton *)setupButtonWithTitle:(NSString *)title{
    
    UIButton * button = [UIButton new];
    
    [button setTitle:title forState:UIControlStateNormal];
    [button setTitleColor:ZRBlackColor forState:UIControlStateNormal];
//    [button setTitleColor:ColorWithRGB(0x909090) forState:UIControlStateNormal];
    [button addTarget:self action:@selector(cilckButton:) forControlEvents:UIControlEventTouchUpInside];
    button.titleLabel.font = [UIFont systemFontOfSize:15 * SCREENH6];
    
    return button;
}


- (void)cilckButton:(UIButton *)button{
    
    NSString * status;
    if(button == self.personButton){
        
        status = @"person";
        if (!button.selected) {
            
            button.selected = YES;
            
            self.personLineView.hidden = NO;
            self.groupButton.selected = NO;
            self.groupLineView.hidden = YES;
        }
    }else{
        status = @"group";
        if (!button.selected) {
            button.selected = YES;
            
            self.groupLineView.hidden = NO;
            self.personButton.selected = NO;
            self.personLineView.hidden = YES;
        }
    }
    
        
    if (self.delegate && [self.delegate respondsToSelector:@selector(clickCategoryButtonWithType:)])
    {
        
        [self.delegate clickCategoryButtonWithType:status];
    }
}

@end
